package com.wlc.collection;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.TreeSet;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description HashSet, LinkedSet ,TreeSet
 * @date 2021-07-12 20:03
 */
public class SetDemo {

    public void method01() {
        HashSet<Integer> hashSet = new HashSet();
        hashSet.add(23);
        hashSet.add(12);
        hashSet.add(34);
        hashSet.add(1);

        LinkedHashSet<Integer> linkedHashSet = new LinkedHashSet<>();
        linkedHashSet.add(23);
        linkedHashSet.add(12);
        linkedHashSet.add(34);
        linkedHashSet.add(1);

        TreeSet<Integer> treeSet = new TreeSet<>();
        treeSet.add(23);
        treeSet.add(12);
        treeSet.add(34);
        treeSet.add(1);

        System.out.print("hashSet = " + hashSet);
        System.out.println();
        System.out.print("linkedHashSet = " + linkedHashSet);
        System.out.println();
        System.out.print("treeSet = " + treeSet);

    }

    public void method02() {
        String s = String.valueOf(Math.PI);
        s = s.replace(".", "");
        char[] chars = s.toCharArray();
        LinkedHashSet<Integer> hashSet = new LinkedHashSet<>();
        for (int i = 0; i < chars.length; i++) {
            hashSet.add(Integer.parseInt(String.valueOf(chars[i])));
        }
        hashSet.forEach(System.out::println);
        //System.out.printf("PI中没有重复的数字是%d", hashSet);

    }

    public static void main(String[] args) {
        new SetDemo().method02();
    }
}
